<template>
  <div class="page-miH page-bgBack">
    <PageHeader @back="goBack">{{ status === "add" ? "新增人员" : "员工报送信息详情" }}</PageHeader>
    <basicInfo :title="'员工基本信息'" :editable="basicInfoFormJson.editable">
      <moduleShow
        ref="basic"
        :title="'员工基本信息'"
        :status="status"
        :dataSource="basicData"
        :editable.sync="basicInfoFormJson.editable"
        :dynamicData="{}"
        :formFields="basicInfoFormJson.fields"
        :sortedKeys="basicInfoFormJson.sortedKeys"
        :formConfig="{}"
        class="pt16"
        style="margin: 0 auto"
        @itemChange="itemChangebasic"
        @change="dynamicChange($event, 'basic', 'basicInfoFormJson', null)"
        @edit="editItem('basicInfoFormJson')"
        @delete="deleteItem('basicInfoFormJson')"
        @cancel="cancelItem('basicInfoFormJson')"
      ></moduleShow>
    </basicInfo>
    <basicInfo :title="'联系方式'" :editable.sync="detailedFormJson.editable">
      <moduleShow
        ref="detailed"
        :title="'联系方式'"
        :status="status"
        :detailedShow="detailedShow"
        :dataSource="detailedData"
        :editable.sync="detailedFormJson.editable"
        :dynamicData="{}"
        :formFields="detailedFormJson.fields"
        :sortedKeys="detailedFormJson.sortedKeys"
        :formConfig="{}"
        class="pt16"
        style="margin: 0 auto"
        @itemChange="itemChangebasic"
        @change="dynamicChange($event, 'detailed', 'detailedFormJson', null)"
        @edit="editItem('detailedFormJson')"
        @delete="deleteItem('detailedFormJson')"
        @cancel="cancelItem('detailedFormJson')"
      ></moduleShow>
    </basicInfo>
    <basicInfo :title="'任职受雇信息'" :editable="employmentFormJson.editable">
      <div v-for="(i, index) in employmentList" :key="i.idNum" class="bore8">
        <moduleShow
          :ref="i.idNum"
          :title="'任职受雇信息'"
          :status="status"
          :remove="status === 'add' ? true : submissionState(i.submissionState)"
          :dataSource="i"
          :editable.sync="i.editable"
          :dynamicData="{}"
          :formFields="i.fields"
          :sortedKeys="i.sortedKeys"
          :formConfig="{}"
          :dataListArr="dataList"
          class="pt16"
          style="margin: 0 auto"
          @itemChange="itemChangebasic"
          @remove="dynamicRemove(i.idNum, index)"
          @change="dynamicChange($event, 'employment', 'employmentFormJson', i.idNum)"
          @edit="editItem('employmentFormJson', i)"
          @delete="deleteItem('employmentFormJson', i)"
          @cancel="cancelItem('employmentFormJson', i)"
        ></moduleShow>
      </div>
    </basicInfo>
    <div style="text-align: center; padding-bottom: 65px">
      <a-button v-if="addEmploymentInfoValShow" @click="addEmploymentInfoVal()"> <a-icon type="plus" />添加任职受雇信息 </a-button>
    </div>
    <div class="boxBottom" v-if="status === 'add'">
      <a-button style="margin-right: 12px" @click="$router.go(-1)">取消</a-button>
      <a-button type="primary" :loading="loading" @click="addSave">完成</a-button>
    </div>
  </div>
</template>
<script>
import { basicInformation, detailedInformation, employmentInformation } from "./dataVal";
import basicInfo from "./basicInformation";
import moduleShow from "./moduleShow";
import { basicsPages } from "./dynamic";
import {
  saveInfo,
  listByEmpId,
  getTaxCompanieslistAll,
  editEmployees,
  addEmployeeRecordsSaveRecord,
  editEmployeeRecords,
  delEmployeeRecords,
  getCompanyAuthoritiesListAll
} from "../api";
export default {
  components: {
    basicInfo,
    moduleShow
  },
  data() {
    return {
      detailedShow: true,
      loading: false,
      addEmploymentInfoValShow: true,
      empId: "",
      basicInformation: basicInformation,
      employmentInformation,
      status: "",
      employmentList: [],
      basicData: {},
      detailedData: {},
      employmentDate: {},
      basicInfoFormJson: {},
      detailedFormJson: {},
      employmentFormJson: {},
      authorityArr: [],
      deleteitem: false,
      employeeVO: {},
      employeeRecords: {},
      disabledDate: null,
      dataList: []
    };
  },

  async mounted() {
    this.status = this.$route.query.status;
    await this.basicInfo();
    await this.getDetailedInfo();
    await this.getEmploymentInformation();
    await this.getCompanyAuthoritiesListAllFun();
    setTimeout(async () => {
      if (this.status === "edit") {
        // 编辑查询
        await this.getListByEmpId(this.$route.query.empId);
      }
    }, 500);
  },
  methods: {
    async getCompanyAuthoritiesListAllFun() {
      try {
        const { data } = await getCompanyAuthoritiesListAll();
        this.dataList = data;
      } catch (err) {
        console.log("error log --> ", err);
      }
    },
    // 任职受雇信息可否展示删除按钮
    submissionState(val) {
      if (val && (val === 2 || val === 4)) {
        return true;
      } else {
        return false;
      }
    },
    getListByEmpId(empId) {
      this.empId = empId;
      // console.log(' this.employmentFormJson.sortedKeys ', this.employmentFormJson.sortedKeys )
      listByEmpId(empId).then((res) => {
        const data = res.data.employeeVO;
        this.employeeVO = data;
        if (data.contactAddressArea) {
          data.contactAddressProvince1 = [data.contactAddressProvince, data.contactAddressCity, data.contactAddressArea];
        } else if (data.contactAddressCity) {
          data.contactAddressProvince1 = [data.contactAddressProvince, data.contactAddressCity];
        } else {
          data.contactAddressProvince1 = null;
        }
        if (data.habitualResidenceArea) {
          data.habitualResidenceProvince1 = [data.habitualResidenceProvince, data.habitualResidenceCity, data.habitualResidenceArea];
        } else if (data.habitualResidenceCity) {
          data.habitualResidenceProvince1 = [data.habitualResidenceProvince, data.habitualResidenceCity];
        } else {
          data.habitualResidenceProvince1 = null;
        }
        if (data.domicileArea) {
          data.domicileProvince1 = [data.domicileProvince, data.domicileCity, data.domicileArea];
        } else if (data.domicileCity) {
          data.domicileProvince1 = [data.domicileProvince, data.domicileCity];
        } else {
          data.domicileProvince1 = null;
        }
        Object.keys(data).forEach((element) => {
          if (data[element] === true) {
            data[element] = "true";
          }
          if (data[element] === false) {
            data[element] = "false";
          }
        });
        this.basicData = data;
        this.detailedData = data;
        this.employmentList = res.data.recordList || [];
        this.employmentList = this.employmentList.map((z, index) => {
          z.idNum = index;
          z.authorityId = [z.companyId, z.authorityId];
          z.companyName = this.dataList.find((y) => y.id === z.companyId).name;
          z.phoneNew = z.phone;
          z.editable = false;
          z.fields = this.employmentFormJson.fields;
          z.sortedKeys = this.employmentFormJson.sortedKeys;
          z.isDeductDeductible = z.isDeductDeductible === true ? "true" : z.isDeductDeductible === false ? "false" : z.isDeductDeductible;
          return z;
        });
        Object.keys(data).forEach((element) => {
          this.itemChangebasic(data[element], element);
        });
        // 用于展示三个银行相关其中一个填写就加必填按钮
        setTimeout(() => {
          if (data.bankCard || data.bankProvince || data.bank) {
            this.detailedFormJson.fields.bankCard.decorator.rules[0].required = true;
            this.detailedFormJson.fields.bankProvince.decorator.rules[0].required = true;
            this.detailedFormJson.fields.bank.decorator.rules[0].required = true;
          }
        }, 500);

        this.employmentList.map((z, index) => {
          this.itemChangebasic(z.totalPersonalInvestment, "totalPersonalInvestment", z);
          this.itemChangebasic(z.employmentType, "employmentType", z);
          this.itemChangebasic(z.status, "status", z);
        });
        this.employmentList.map((z, index) => {
          z.fields.authorityId.customize.disabled = true;
          return z;
        });
      });
    },
    addEmploymentInfoVal(text) {
      this.employeeRecords = {};
      if (this.employmentList.length === 0) {
        this.employmentList.push({
          idNum: 0,
          editable: true,
          fields: this.employmentFormJson.fields,
          sortedKeys: this.employmentFormJson.sortedKeys
        });
      } else {
        if (!text && this.status !== "add") {
          this.employmentList.filter((z) => (z.editable = false));
        }
        this.employmentList.push({
          idNum: this.employmentList[this.employmentList.length - 1].idNum + 1,
          editable: true,
          fields: this.employmentFormJson.fields,
          sortedKeys: this.employmentFormJson.sortedKeys
        });
      }
      if (this.status !== "add") {
        this.addEmploymentInfoValShow = !!text;
      }
    },
    dynamicRemove(id, index) {
      this.employmentList.splice(index, 1);
      this.addEmploymentInfoValShow = true;
    },
    dynamicChange(value, sign, edit, idNum) {
      console.log("value", value);
      if (sign === "basic" || sign === "detailed") {
        if (value.contactAddressProvince1) {
          if (value.contactAddressProvince1.length === 3) {
            value.contactAddressArea = value.contactAddressProvince1[2];
          }
          value.contactAddressCity = value.contactAddressProvince1[1];
          value.contactAddressProvince = value.contactAddressProvince1[0];
        }
        if (value.contactAddressProvince1 && value.contactAddressProvince1.length === 0) {
          value.contactAddressArea = null;
          value.contactAddressCity = null;
          value.contactAddressProvince = null;
        }
        if (value.habitualResidenceProvince1) {
          if (value.habitualResidenceProvince1.length === 3) {
            value.habitualResidenceArea = value.habitualResidenceProvince1[2];
          }
          value.habitualResidenceCity = value.habitualResidenceProvince1[1];
          value.habitualResidenceProvince = value.habitualResidenceProvince1[0];
        }
        if (value.habitualResidenceProvince1 && value.habitualResidenceProvince1.length === 0) {
          value.habitualResidenceArea = null;
          value.habitualResidenceCity = null;
          value.habitualResidenceProvince = null;
        }
        if (value.domicileProvince1) {
          if (value.domicileProvince1.length === 3) {
            value.domicileArea = value.domicileProvince1[2];
          }
          value.domicileCity = value.domicileProvince1[1];
          value.domicileProvince = value.domicileProvince1[0];
        }
        if (value.domicileProvince1 && value.domicileProvince1.length === 0) {
          value.domicileArea = null;
          value.domicileCity = null;
          value.domicileProvince = null;
        }
        value.id = this.empId;
        let data = {};
        if (sign === "basic") {
          data = Object.assign(this.basicData, value);
        } else {
          data = Object.assign(this.detailedData, value);
        }
        // console.log('data',data)
        const that = this;
        this.$confirm({
          title: "确定要修改个税档案吗？",
          content: "系统修改后，若想修改税局人员报送信息，请再次报送",
          onOk() {
            editEmployees(data).then((res) => {
              that.$notification["success"]({
                message: res.msg
              });
              that[edit].editable = false;
              that.getListByEmpId(that.empId);
              that.addEmploymentInfoValShow = true;
            });
          },
          onCancel() {}
        });
      } else {
        if (this.employeeRecords.id) {
          // 编辑
          const that = this;
          this.$confirm({
            title: "确定要修改个税档案吗？",
            content: "系统修改后，若想修改税局人员报送信息，请再次报送",
            onOk() {
              editEmployeeRecords({
                licenseNumber: that.employeeVO.licenseNumber,
                empName: that.employeeVO.name,
                ...value,
                resignDate: value.resignDate ? value.resignDate : "",
                phone: value.phoneNew,
                companyId: value.authorityId[0],
                authorityName: that.authorityArr.find((y) => y.value === value.authorityId[1]).label,
                companyName: that.dataList.find((y) => y.id === value.authorityId[0]).name,
                authorityId: value.authorityId[1],
                empId: that.empId,
                id: that.employeeRecords.id
              }).then((res) => {
                that.$notification["success"]({
                  message: res.msg
                });
                that.employmentList.forEach(function (item, index, arr) {
                  if (item.idNum === idNum) {
                    item.editable = false;
                  }
                });
                that.getListByEmpId(that.empId);
                that.addEmploymentInfoValShow = true;
              });
            },
            onCancel() {}
          });
        } else {
          // 新增
          addEmployeeRecordsSaveRecord({
            licenseNumber: this.employeeVO.licenseNumber,
            ...value,
            phone: value.phoneNew,
            companyId: value.authorityId[0],
            authorityName: this.authorityArr.find((y) => y.value === value.authorityId[1]).label,
            companyName: this.dataList.find((y) => y.id === value.authorityId[0]).name,
            authorityId: value.authorityId[1],
            empId: this.empId,
            empName: this.employeeVO.name
          }).then((res) => {
            this.$notification["success"]({
              message: res.msg
            });
            this.employmentList.forEach(function (item, index, arr) {
              if (item.idNum === idNum) {
                item.editable = false;
              }
            });
            this.getListByEmpId(this.empId);
            this.addEmploymentInfoValShow = true;
          });
        }
        this.employmentFormJson.editable = false;
      }
    },
    addSave() {
      this.loading = true;
      const basic = this.$refs.basic.saveReturn();
      const detailed = this.$refs.detailed.saveReturn();
      const data = this.employmentList.map((res, index) => {
        return this.$refs[res.idNum][0].saveReturn();
      });
      let data1 = null;
      let data2 = null;
      Promise.all([basic, detailed])
        .then((result) => {
          data1 = result;
        })
        .catch((err) => {
          console.log(err);
          this.loading = false;
        });
      Promise.all(data)
        .then((result) => {
          data2 = result.map((z) => {
            if (z.authorityId) {
              z.companyName = this.dataList.find((y) => y.id === z.authorityId[0]).name;
              z.companyId = z.authorityId[0];
              z.authorityName = this.authorityArr.find((y) => y.value === z.authorityId[1]).label;
              z.authorityId = z.authorityId[1];
            }
            return z;
          });
        })
        .catch((err) => {
          console.log(err);
          this.loading = false;
        });
      setTimeout(() => {
        if (data1 && data2) {
          data2 = data2.map((z) => {
            z.phone = z.phoneNew;
            return z;
          });
          const data = { ...data1[0], ...data1[1], recordAddDTOList: data2 };
          this.saveInfo(data);
        }
      }, 500);
    },
    saveInfo(data) {
      Object.keys(data).forEach((element) => {
        if (data[element] === "true") {
          data[element] = true;
        }
        if (data[element] === "false") {
          data[element] = false;
        }
      });
      if (data.contactAddressProvince1) {
        if (data.contactAddressProvince1.length === 3) {
          data.contactAddressArea = data.contactAddressProvince1[2];
        }
        data.contactAddressCity = data.contactAddressProvince1[1];
        data.contactAddressProvince = data.contactAddressProvince1[0];
      }
      if (data.habitualResidenceProvince1) {
        if (data.habitualResidenceProvince1.length === 3) {
          data.habitualResidenceArea = data.habitualResidenceProvince1[2];
        }
        data.habitualResidenceCity = data.habitualResidenceProvince1[1];
        data.habitualResidenceProvince = data.habitualResidenceProvince1[0];
      }
      if (data.domicileProvince1) {
        if (data.domicileProvince1.length === 3) {
          data.domicileArea = data.domicileProvince1[2];
        }
        data.domicileCity = data.domicileProvince1[1];
        data.domicileProvince = data.domicileProvince1[0];
      }
      data.licenseNumber = data.licenseNumber.toUpperCase(); // 身份证字符大写

      saveInfo(data)
        .then((res) => {
          this.$notification["success"]({
            message: res.msg
          });
          this.$router.go(-1);
          setTimeout(() => {
            this.loading = false;
          }, 500);
        })
        .catch((err) => {
          console.log(err);
          this.loading = false;
        });
    },
    getBirth(idCard) {
      var birthday = "";
      if (idCard !== null && idCard !== "") {
        if (idCard.length === 15) {
          birthday = "19" + idCard.slice(6, 12);
        } else if (idCard.length === 18) {
          birthday = idCard.slice(6, 14);
        }
        birthday = birthday.replace(/(.{4})(.{2})/, "$1-$2-");
      }
      return birthday;
    },
    getSex(idCard) {
      var sexStr = "";
      if (parseInt(idCard.slice(-2, -1)) % 2 === 1) {
        sexStr = "1";
      } else {
        sexStr = "2";
      }
      return sexStr;
    },
    GetDateDiff(time1, time2) {
      time1 = new Date(time1); // 转换为中国标准时间
      time2 = new Date(time2);
      time1 = time1.getTime(); // 转换为时间戳
      time2 = time2.getTime();
      var runTime = (time2 - time1) / 1000; // 开始得出时间差,然后计算
      var year = Math.floor(runTime / 86400 / 365);
      runTime = runTime % (86400 * 365);
      var month = Math.floor(runTime / 86400 / 30);
      runTime = runTime % (86400 * 30);
      var day = Math.floor(runTime / 86400);
      runTime = runTime % 86400;
      var hour = Math.floor(runTime / 3600);
      runTime = runTime % 3600;
      var minute = Math.floor(runTime / 60);
      runTime = runTime % 60;
      var second = runTime;
      return year + "," + month + "," + day;
    },
    itemChangebasic(val, name, dataSource) {
      if (name === "licenseNumber") {
        this.$set(this.basicData, "gender", val.length === 18 || val.length === 15 ? this.getSex(val) : null);
        this.$set(this.basicData, "birthday", val.length === 18 || val.length === 15 ? this.getBirth(val) : null);
      } else if (name === "isDisable") {
        if (val === true || val === "true") {
          this.basicInfoFormJson.sortedKeys.map((z, index) => {
            if (z === "isDisable" && !this.basicInfoFormJson.sortedKeys.includes("disableCard")) {
              const tempKeys = [...this.basicInfoFormJson.sortedKeys];
              tempKeys.splice(index + 1, 0, "disableCard");
              this.basicInfoFormJson.sortedKeys = tempKeys;
            }
          });
        } else if (val === false || val === "false") {
          this.basicInfoFormJson.sortedKeys.forEach(function (item, index, arr) {
            if (item === "disableCard") {
              arr.splice(index, 1);
            }
          });
        }
      } else if (name === "isMartyr") {
        if (val === true || val === "true") {
          this.basicInfoFormJson.sortedKeys.map((z, index) => {
            if (z === "isMartyr" && !this.basicInfoFormJson.sortedKeys.includes("martyrCard")) {
              const tempKeys = [...this.basicInfoFormJson.sortedKeys];
              tempKeys.splice(index + 1, 0, "martyrCard");
              this.basicInfoFormJson.sortedKeys = tempKeys;
            }
          });
        } else if (val === false || val === "false") {
          this.basicInfoFormJson.sortedKeys.forEach(function (item, index, arr) {
            if (item === "martyrCard") {
              arr.splice(index, 1);
            }
          });
        }
      } else if (name === "totalPersonalInvestment") {
        const target = this.employmentList.find((item) => item.idNum === dataSource.idNum);
        if (val || val === 0) {
          if (!target.sortedKeys.includes("personalInvestmentRatio")) {
            target.sortedKeys.map((z, index) => {
              if (z === "totalPersonalInvestment") {
                const tempKeys = [...target.sortedKeys];
                tempKeys.splice(index + 1, 0, "personalInvestmentRatio");
                this.employmentList = this.employmentList.map((item1, index) => {
                  if (item1.idNum === target.idNum) {
                    item1.sortedKeys = tempKeys;
                  }
                  return item1;
                });
              }
            });
          }
        } else {
          target.sortedKeys.forEach(function (item, index, arr) {
            if (item === "personalInvestmentRatio") {
              arr.splice(index, 1);
            }
          });
          this.employmentList = this.employmentList.map((item1, index) => {
            if (item1.idNum === target.idNum) {
              item1.sortedKeys = target.sortedKeys;
            }
            return item1;
          });
        }
      } else if (name === "employmentType") {
        const target = this.employmentList.find((item) => item.idNum === dataSource.idNum);

        if (val === "10" || val === "20" || val === "30") {
          if (!target.sortedKeys.includes("employmentSituation")) {
            target.sortedKeys.map((z, index) => {
              if (z === "employmentType") {
                const tempKeys = [...target.sortedKeys];
                tempKeys.splice(index + 1, 0, "employmentSituation");
                // target.sortedKeys = tempKeys;
                this.employmentList = this.employmentList.map((item1, index) => {
                  if (item1.idNum === target.idNum) {
                    item1.sortedKeys = tempKeys;
                  }
                  return item1;
                });
              }
            });
          }
        } else {
          target.sortedKeys.forEach(function (item, index, arr) {
            if (item === "employmentSituation") {
              arr.splice(index, 1);
            }
          });
          this.employmentList = this.employmentList.map((item1, index) => {
            if (item1.idNum === target.idNum) {
              item1.sortedKeys = target.sortedKeys;
            }
            return item1;
          });
        }
      } else if (name === "resignDate") {
        const employedDate = this.$refs[dataSource.idNum][0].getFieldValue("employedDate")
          ? this.$refs[dataSource.idNum][0].getFieldValue("employedDate").format("YYYY-MM-DD")
          : null;
        if (employedDate) {
          const num = this.GetDateDiff(employedDate, val)
            .split(",")
            .find((z) => z < 0);
          if (num) {
            this.$message.error("离职日期不能小于任职受雇从业日期");
            this.$nextTick(() => {
              this.$refs[dataSource.idNum][0].setFieldsValueShow("resignDate", null);
            });
          }
        }
      } else if (name === "employedDate") {
        const resignDate = this.$refs[dataSource.idNum][0].getFieldValue("resignDate")
          ? this.$refs[dataSource.idNum][0].getFieldValue("resignDate").format("YYYY-MM-DD")
          : null;
        if (resignDate) {
          const num = this.GetDateDiff(val, resignDate)
            .split(",")
            .find((z) => z < 0);
          if (num) {
            this.$message.error("任职受雇从业日期不能大于离职日期");
            this.$nextTick(() => {
              this.$refs[dataSource.idNum][0].setFieldsValueShow("employedDate", null);
            });
          }
        }
      } else if (name === "status") {
        const data = JSON.parse(JSON.stringify(this.employmentList));
        data.map((item) => {
          if (item.idNum === dataSource.idNum) {
            if (val === 2) {
              item.fields.resignDate.decorator.rules[0].required = true;
            } else {
              item.fields.resignDate.decorator.rules[0].required = false;
            }
          }
          return item;
        });
        this.employmentList = JSON.parse(JSON.stringify(data)).map((z) => {
          z.fields.resignDate.customize.disabledDate = this.disabledDate;
          z.fields.employedDate.customize.disabledDate = this.disabledDate;
          return z;
        });
      } else if (name === "bankCard" || name === "bankProvince" || name === "bank") {
        this.$set(this.detailedData, name, val);
        this.$nextTick(() => {
          if (
            this.$refs.detailed.getFieldValue("bankCard") ||
            this.$refs.detailed.getFieldValue("bankProvince") ||
            this.$refs.detailed.getFieldValue("bank")
          ) {
            this.$set(this.detailedFormJson.fields.bankCard.decorator.rules[0], "required", true);
            this.$set(this.detailedFormJson.fields.bankProvince.decorator.rules[0], "required", true);
            this.$set(this.detailedFormJson.fields.bank.decorator.rules[0], "required", true);
          } else {
            this.$set(this.detailedFormJson.fields.bankCard.decorator.rules[0], "required", false);
            this.$set(this.detailedFormJson.fields.bankProvince.decorator.rules[0], "required", false);
            this.$set(this.detailedFormJson.fields.bank.decorator.rules[0], "required", false);
            this.detailedShow = false;
            this.$nextTick(() => {
              this.detailedShow = true;
            });
          }
        });
      }
    },
    basicInfo() {
      this.basicInfoFormJson = {
        editable: this.status === "add",
        fields: {},
        sortedKeys: {}
      };
      const { fields, fieldKeys } = basicsPages(basicInformation[0].moduleCode, basicInformation, this.status);
      this.basicInfoFormJson.fields = fields;
      if (this.status === "add") {
        fieldKeys.forEach(function (item, index, arr) {
          if (item === "disableCard" || item === "martyrCard") {
            arr.splice(index, 1);
          }
        });
        this.$set(this.basicData, "licenseType", "10");
        this.$set(this.basicData, "nationality", "中国");
      } else {
        this.$set(this.basicInfoFormJson.fields.licenseNumber.customize, "disabled", true);
      }
      this.basicInfoFormJson.sortedKeys = fieldKeys;
    },
    getDetailedInfo() {
      this.detailedFormJson = {
        editable: this.status === "add",
        fields: {},
        sortedKeys: {}
      };
      const { fields, fieldKeys } = basicsPages(detailedInformation[0].moduleCode, detailedInformation, this.status);
      this.detailedFormJson.fields = fields;
      this.detailedFormJson.sortedKeys = fieldKeys;
    },
    getEmploymentInformation() {
      this.employmentFormJson = {
        editable: this.status === "add",
        fields: {},
        sortedKeys: {}
      };
      getTaxCompanieslistAll({ companyId: this.$store.state.hr.companyId }).then((res) => {
        const data = res.data.map((z) => {
          return {
            label: z.responsibleAuthorityName,
            value: z.id,
            companyId: z.companyId,
            companyName: z.withholdingAgentName
          };
        });
        this.authorityArr = data;
        const employmentInformationdata = employmentInformation.map((z) => {
          if (z.fieldCode === "authorityId") {
            z.dropDownEnumList = data;
          }
          return z;
        });
        const { fields, fieldKeys } = basicsPages(employmentInformation[0].moduleCode, employmentInformationdata, this.status);
        this.employmentFormJson.fields = fields;
        this.employmentFormJson.sortedKeys = fieldKeys;
        this.disabledDate = this.employmentFormJson.fields.resignDate.customize.disabledDate;
        if (this.status === "add") {
          this.addEmploymentInfoVal("have");
        }
        this.employmentFormJson.sortedKeys.forEach(function (item, index, arr) {
          if (item === "personalInvestmentRatio") {
            arr.splice(index, 1);
          }
        });
      });
    },
    goBack() {
      this.$router.go(-1);
    },
    editItem(sign, item) {
      if (sign === "employmentFormJson") {
        this.employmentList = this.employmentList.map((z) => {
          if (z.idNum === item.idNum) {
            z.editable = true;
          } else {
            z.editable = false;
          }
          return z;
        });
        this.employeeRecords = item;
      } else {
        this[sign].editable = true;
      }
      this.addEmploymentInfoValShow = false;
    },
    cancelItem(sign, item) {
      if (sign === "employmentFormJson") {
        this.employmentList = this.employmentList.map((z) => {
          if (z.idNum === item.idNum) {
            z.editable = false;
          }
          return z;
        });
      } else {
        this[sign].editable = false;
      }
      this.addEmploymentInfoValShow = true;
      this.getListByEmpId(this.$route.query.empId);
    },
    deleteItem(sign, item) {
      if (item.id) {
        const that = this;
        this.$confirm({
          title: "是否确认删除任职受雇信息?",
          content: "本系统删除后，若想修改税局人员报送信息，请再次报送",
          onOk() {
            delEmployeeRecords(item.id).then((res) => {
              that.$notification["success"]({
                message: res.msg
              });
              that.getListByEmpId(that.empId);
            });
          },
          onCancel() {}
        });
      } else {
        for (var i = 0; i < this.employmentList.length; i++) {
          if (this.employmentList[i].idNum === item.idNum) {
            this.employmentList.splice(i, 1);
          }
        }
      }
      this.addEmploymentInfoValShow = true;
    }
  }
};
</script>
<style lang="scss" scoped>
.boxBottom {
  width: 100%;
  height: 56px;
  line-height: 56px;
  background: #ffffff;
  text-align: center;
  box-shadow: 0px 0px 7px 0px rgba(0, 0, 0, 0.15);
  position: fixed;
  bottom: 0;
  padding-right: 204px;
}
.bore8 {
  padding-bottom: 5px;
  // border-bottom: 1px solid #e8e8e8;
}
.peopleBoxCon1 .bore8:nth-last-child(1) {
  border-bottom: 0;
}
</style>
